#include<iostream>
#include<cmath>
using namespace std;
#define int long long
const int N = 1e6+11;
int n,a[N],b[N>>1];

signed main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    int j=0;
    for(int i=1;i<=n/2;++i)
    {
        b[++j]=a[i]-a[n-i+1];
    }
    
    int len=j,ans=0;
    for(int i=1;i<=len;++i)
    {
        ans+=abs(b[i]);
        if(i!=n)
        {
            if(b[i]>0&&b[i+1]>0)
            {
                b[i+1]-=min(b[i],b[i+1]);
            }
            if(b[i]<0&&b[i+1]<0)
            {
                b[i+1]-=max(b[i],b[i+1]);
            }
        }
    }
    cout<<ans;
    return 0;
}